import ajax from "@/common/ajax";
import mock from "../mock/index";
import { MenuResponse, LoginApi, DocInfoResponse, ResponseData,AppResponse } from "@/types"

// const request = import.meta.env.REACT_APP_MOCK === '1' ? mock : ajax; // 手动修改env信息
const request = ajax; // 手动修改env信息

const login = (data: any) => request.post("/login", data) as Promise<LoginApi>;
// 获取菜单信息
const getMenu = (data:any) => request.get(`/cloud/doc?directory_key=${data}`,data) as Promise<MenuResponse>;
// 菜单详情内容
const getDocDetail = (data:any) => request.get(`/cloud/doc/${data}`, data) as Promise<DocInfoResponse>;
// 删除菜单
const delDoc = (data:any) => request.delete(`/cloud/doc/${data}`, data) as Promise<DocInfoResponse>;
// 编辑保存
const editDocContent = (uuid:any,data: any) =>
  request.put(`/cloud/doc/${uuid}`, data) as Promise<ResponseData>;
  // 菜单
const addMenu = (data:any) => request.post(`/cloud/doc`, data) as Promise<DocInfoResponse>;
// 建议
const handleSugg = (data: any) => request.post("/cloud/doc/proposal", data) as Promise<LoginApi>;
  // 点赞
  const addEvaluate = (data: any) =>
  request.get(`/evaluate?docId=${data.docId}&&type=${data.type}`, data) as Promise<ResponseData>;
// 获取菜单信息
const getAppList = () => request.get(`/cloud/doc/directory`) as Promise<AppResponse>;
const addApp = (data:any) => request.post(`/cloud/doc/directory`,data) as Promise<DocInfoResponse>;
  const addImage = (data:any) => request.post(`/cloud/doc/image`, data, { headers:{'Content-type' : 'multipart/form-data'}}) as Promise<DocInfoResponse>;  

  export {
  login,
  getMenu,
  getDocDetail,
  addEvaluate,
  editDocContent,
  delDoc,
  addMenu,
  addImage,
  getAppList,
  addApp,
  handleSugg
};
